package Game;
import java.io.Serializable;

/**
 * Donkey.java
 * 
 * This class represents a Donkey object in the Oregon Trail game. In the game, a Donkey
 * is required to pull a player's cart. A Donkey can ve a vehicle on its own, or part of a cart
 * 
 * @author Ray DeCuir
 * @version 1.0
 */
public class Donkey extends Vehicle implements Serializable{

	// the vehicleNode that holds the donkey object
	private VehicleNode donkey;
	
	// the donkey's health status
	private HealthState healthStatus;
	
	// double that manages the sliding scale between health states
	private double healthSlider;

	/**
	 * Constructor for a Donkey object. Creates a new Donkey 
	 */
	public Donkey()
	{
		parts = new VehicleNode[1];
		this.weightCapacity = GameDriver.getItemList().getItemWeight( GameDriver.getItemList().getIdOf("name", "Donkey") );
		donkey = new VehicleNode( GameDriver.getItemList().getIdOf("name", "Donkey") );
		parts[0] = donkey;
	}


	/**
	 * @return the healthStatus
	 */
	public HealthState getHealthStatus() {
		return healthStatus;
	}


	/**
	 * @param healthStatus the healthStatus to set
	 */
	public void setHealthStatus(HealthState healthStatus) {
		this.healthStatus = healthStatus;
		healthSlider = healthStatus.getIndex();
	}
	
	/**
	 * Updates the donkey's health status and on the pace, a grueling pace will reduce it of 
	 * these while a resting pace will increase it
	 * 
	 * @param playerPace
	 */
	public void travelUpdate(Pace playerPace)
	{
		if ( isAlive() )
		{
			healthSlider = healthSlider + 0.3 * ( 1.5 - 2 * playerPace.getMulti()  );
			int hs = (int)Math.round(healthSlider);
			if ( hs < 0)
				hs = 0;
			else if (hs > 5)
				hs = 5;
			healthStatus = HealthState.values()[hs];
		}
	}
	
	
	/**
	 * Returns a boolean denoting if the Donkey is alive
	 * 
	 * @return A boolean denoting if the Donkey is alive
	 */
	public boolean isAlive()
	{
		return this.healthStatus != HealthState.DEAD;
	}
	
	
	/**
	 * Gets the donkey object for another class
	 * 
	 * @return The instance of donkey represented by the class
	 */
	public Donkey getDonkey()
	{
		return this;
	}
}
